package me.zhengjie.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "fz_chunk")
@Getter
@Setter
@GenericGenerator(name = "id", strategy = "uuid")
public class ErpChunk implements Serializable {
    private static final long serialVersionUID = 7073871700302406420L;

    @Id
    private String id;
    /**
     * 当前文件块，从1开始
     */
    private Integer chunkNumber;
    /**
     * 分块大小
     */
    private Long chunkSize;
    /**
     * 当前分块大小
     */
    private Long currentChunkSize;
    /**
     * 总大小
     */
    private Long totalSize;
    /**
     * 文件标识
     */
    private String identifier;
    /**
     * 文件名
     */
    private String filename;
    /**
     * 相对路径
     */
    private String relativePath;
    /**
     * 总块数
     */
    private Integer totalChunks;
    /**
     * 文件类型
     */
    private String type;
    private String bId;
    private String fType;

    /**
     * 要上传的文件
     */
    @Transient
    private MultipartFile file;

    @Transient
    private String parentId;

    public void copy(ErpChunk source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    public void copyTo(ErpChunk source){
        BeanUtil.copyProperties(this, source, CopyOptions.create().setIgnoreNullValue(true));
    }
}
